// ToolControlBar.cpp: implementation of the CToolControlBar class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "resource.h"
#include "ToolControlBar.h"
#include "SkinToolBar.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSkinToolControlBar::CSkinToolControlBar()
{

}
CObList gToolBarList;

CSkinToolControlBar::~CSkinToolControlBar()
{
	POSITION pos;
	pos = gToolBarList.GetHeadPosition();
	while( pos )
	{
		CObject *ob = gToolBarList.GetAt(pos);
			delete (CSkinToolBar *)ob;
		gToolBarList.GetNext(pos);
	}		
	gToolBarList.RemoveAll();
				
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam )
{
	CSkinToolBar *pToolBar = new CSkinToolBar();
	gToolBarList.AddTail(pToolBar);
	pToolBar->HookWindow((HWND)hwnd);
	
	return 0;
}

LRESULT CSkinToolControlBar::WindowProc( UINT msg, WPARAM wp, LPARAM lp )
{
	if ( !IsWindow(m_hWnd) )
		return 0;
	switch ( msg )
	{
 
 	case WM_PAINT:
//  		ShowWindow(m_hWnd,SW_HIDE);
//  		SendMessage(GetParent(m_hWnd),WM_SIZE,0,0);
 		return 1;
 
  //		return SendMessage(m_hWnd,WM_DESTROY,0,0);
// 	case WM_SHOWWINDOW:
// 		ShowWindow(m_hWnd,SW_HIDE);
// 		return 1;
	case WM_SIZE:
		{
			int x,y,cx,cy;
			int cxParent = LOWORD (lp);
			int cyParent = HIWORD (lp);
			// Get Toolbar window hieght 
			CRect rc;
			GetWindowRect(m_hWnd,&rc);
			rc.OffsetRect(0,20);

			cy = rc.Height();
			x=0;
			y=cyParent - cy;
			cx = cxParent;
			MoveWindow(m_hWnd,0,0,cx,cy,FALSE);
		}
		return 1;
	default:
		return Default();
	}
	return 0;
}

void CSkinToolControlBar::HookToolbars()
{
	EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0);
}
